namespace DotNetNuke.Modules.Admin.ResourceInstaller
{
    using DotNetNuke.Entities.Modules;
    using System;
    using System.Xml;

    /// -----------------------------------------------------------------------------
    /// <summary>
    /// The PaDnnAdapter_V3 extends PaDnnAdapter_V2 to support V3 Modules
    /// </summary>
    /// <remarks>
    /// </remarks>
    /// <history>
    /// [cnurse]	04/21/2005  documented
    /// </history>
    /// -----------------------------------------------------------------------------
    public class PaDnnAdapter_V3 : PaDnnAdapter_V2
    {
        public PaDnnAdapter_V3(PaInstallInfo InstallerInfo) : base(InstallerInfo)
        {
        }

        protected override PaFolder GetFolderAttributesFromNode(XmlElement FolderElement)
        {
            PaFolder folder = base.GetFolderAttributesFromNode(FolderElement);
            XmlElement businessControllerElement = (XmlElement) FolderElement.SelectSingleNode("businesscontrollerclass");
            if (businessControllerElement != null)
            {
                folder.BusinessControllerClass = businessControllerElement.InnerText.Trim();
            }
            XmlElement friendlynameElement = (XmlElement) FolderElement.SelectSingleNode("friendlyname");
            if (friendlynameElement != null)
            {
                folder.FriendlyName = friendlynameElement.InnerText.Trim();
                folder.ModuleName = friendlynameElement.InnerText.Trim();
            }
            XmlElement foldernameElement = (XmlElement) FolderElement.SelectSingleNode("foldername");
            if (foldernameElement != null)
            {
                folder.FolderName = foldernameElement.InnerText.Trim();
            }
            XmlElement modulenameElement = (XmlElement) FolderElement.SelectSingleNode("modulename");
            if (modulenameElement != null)
            {
                folder.ModuleName = modulenameElement.InnerText.Trim();
            }
            return folder;
        }

        protected override ModuleControlInfo GetModuleControlFromNode(string Foldername, int TempModuleID, XmlElement ModuleControl)
        {
            ModuleControlInfo ModControl = base.GetModuleControlFromNode(Foldername, TempModuleID, ModuleControl);
            if (ModControl != null)
            {
                XmlElement helpElement = (XmlElement) ModuleControl.SelectSingleNode("helpurl");
                if (helpElement != null)
                {
                    ModControl.HelpURL = helpElement.InnerText.Trim();
                }
            }
            return ModControl;
        }

        protected override void LogValidFormat()
        {
            this.InstallerInfo.Log.AddInfo(string.Format(base.DNN_Valid, "3.0"));
        }
    }
}

